package com.cgnpc.scp.run.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.run.mybatis.entity.*;
import com.cgnpc.scp.run.service.ProjectUndertakeService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**********************************
 * 用途说明: 项目承揽界面控制器
 * 作者姓名: zhangyibing
 * 创建时间: 2020年9月14日17:09:41
 ***********************************/
@RestController
@RequestMapping("/run/projectUndertake")
public class ProjectUndertakeController {
    private static final Logger LOGGER = LoggerFactory.getLogger(MarketInfoController.class);

    @Autowired
    private ProjectUndertakeService projectUndertakeService;

    @Autowired
    private MessageSource messageSource;

    /**********************************
     * 用途说明: 组建项目承揽团队
     * 参数说明 projectTeam 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="组建项目承揽团队")
    @UBA(module = "调试经营管理", action = "组建项目承揽团队", channel = OperatorType.Button)
    @RequestMapping(value = "/team", method = {RequestMethod.POST})
    public AjaxResult saveOrUpdateTeam(HttpServletRequest request, @RequestBody ProjectTeam projectTeam){
        try {
            return projectUndertakeService.saveOrUpdateTeam(projectTeam);
        } catch (Exception e) {
            LOGGER.error("ProjectUndertakeController team error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 项目评审
     * 参数说明 projectView 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="项目评审")
    @UBA(module = "调试经营管理", action = "项目评审", channel = OperatorType.Button)
    @RequestMapping(value = "/review", method = {RequestMethod.POST})
    public AjaxResult saveOrUpdateView(HttpServletRequest request, @RequestBody ProjectReview projectReview){
        try {
            return projectUndertakeService.saveOrUpdateReview(projectReview);
        } catch (Exception e) {
            LOGGER.error("ProjectUndertakeController review error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 承揽阶段WBS及预算申请
     * 参数说明 projectView 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="承揽阶段WBS及预算申请")
    @UBA(module = "调试经营管理", action = "承揽阶段WBS及预算申请", channel = OperatorType.Button)
    @RequestMapping(value = "/wbs", method = {RequestMethod.POST})
    public AjaxResult wbs(HttpServletRequest request, @RequestBody ProjectWbs projectWbs){
        try {
            return projectUndertakeService.wbs(projectWbs);
        } catch (Exception e) {
            LOGGER.error("ProjectUndertakeController wbs error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 主任室决策
     * 参数说明 ProjectDirectorMaking 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="主任室决策")
    @UBA(module = "调试经营管理", action = "主任室决策", channel = OperatorType.Button)
    @RequestMapping(value = "/directorMaking", method = {RequestMethod.POST})
    public AjaxResult directorMaking(HttpServletRequest request, @RequestBody ProjectDirectorMaking projectDirectorMaking){
        try {
            return projectUndertakeService.directorMaking(projectDirectorMaking);
        } catch (Exception e) {
            LOGGER.error("ProjectUndertakeController directorMaking error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 投标报价
     * 参数说明 ProjectTenderOffer 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="投标报价")
    @UBA(module = "调试经营管理", action = "投标报价", channel = OperatorType.Button)
    @RequestMapping(value = "/tenderOffer", method = {RequestMethod.POST})
    public AjaxResult tenderOffer(HttpServletRequest request, @RequestBody ProjectTenderOffer projectTenderOffer){
        try {
            return projectUndertakeService.tenderOffer(projectTenderOffer);
        } catch (Exception e) {
            LOGGER.error("ProjectUndertakeController tenderOffer error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 合同推荐
     * 参数说明 ProjectHt 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="合同推荐")
    @UBA(module = "调试经营管理", action = "合同推荐", channel = OperatorType.Button)
    @RequestMapping(value = "/ht", method = {RequestMethod.POST})
    public AjaxResult ht(HttpServletRequest request, @RequestBody ProjectHt projectHt){
        try {
            return projectUndertakeService.ht(projectHt);
        } catch (Exception e) {
            LOGGER.error("ProjectUndertakeController ht error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
